const {
  QUERY_LATEST,
  QUERY_ALL,
  RESPONSE_BLOCKCHAIN
} = require('./message-type');

class Messages {
  getQueryChainLengthMsg () {
    console.log('⬆  向节点询问最新数据块');
    return {
      type: QUERY_LATEST
    }
  }

  getQueryAllMsg () {
    console.log('⬆  向节点询问整个区块链');
    return {
      type: QUERY_ALL
    }
  }

  getResponseChainMsg (blockchain) {
    console.log('⬆  发送整个区块链');
    return {
      type: RESPONSE_BLOCKCHAIN,
      data: JSON.stringify(blockchain.get())
    }
  }

  getResponseLatestMsg (blockchain) {
    console.log('⬆  正在发送节点最新块');
    return {
      type: RESPONSE_BLOCKCHAIN,
      data: JSON.stringify([
        blockchain.latestBlock
      ])
    }
  }
}

const messages = new Messages()
module.exports = messages